package demo.Socket_learn.URL_use;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/16-08-16-14:59
 * @Description：demo.Socket_learn.URL_use
 */
public class url_learn {
    public static void main(String[] args) {
        //创建URL对象  网址
        URL url;
        BufferedReader reader = null;
        try {
            url = new URL("https://www.baidu.com");
            //打开会话，建立连接
            URLConnection conn = url.openConnection();
            //获取返回信息
            reader= new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String str = null;
            while((str = reader.readLine()) != null){
                System.out.println(str);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if(reader != null){
                    reader.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
